package com.kgc.scheduled;

import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @Author: luo
 * @date: 2024/4/6 22:14
 * @Description:
 * @Version: 1.0
 */
@Component
@PropertySource("classpath:task.ini")
@Slf4j
//@EnableScheduling
public class MyScheduleTack2 implements SchedulingConfigurer {

    @Value("${my.cron}")
    private String cron;

    //配置定时任务
    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        //注册触发任务
//        taskRegistrar.addTriggerTask(() -> {
//            //任务要做的事情
//            log.info("系统时间:{}", LocalDateTime.now());
//        },triggerContext -> {
//            if (Strings.isBlank(cron)){
//                cron = "0/5 * * * * ?";
//            }
//            return new CronTrigger(cron).nextExecutionTime(triggerContext).toInstant();
//        });
    }
}
